package com.xuexiang.xuidemo.slice;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.ability.PopupWindowAbility;
import com.xuexiang.xuidemo.dialog.PopupWindowDialog;
import com.xuexiang.xuidemo.util.ToastUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.agp.window.dialog.IDialog;
import ohos.app.Context;

/**
 * 弹出框统一样式
 */
public class PopupWindowStyleSlice extends AbilitySlice implements Component.ClickedListener {
    private Context mContext;
    private Text text_title,text_menu_popup;
    private Image image_back;
    private Button btn_commonlist_popup,btn_expandable_popup,btn_menu_popup;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_popup_window_style);
        initComponent();
        inintClickedListener();
    }

    private void initComponent() {
        mContext= PopupWindowStyleSlice.this;
        image_back = (Image) findComponentById(ResourceTable.Id_image_back);
        text_title = (Text) findComponentById(ResourceTable.Id_text_title);
        text_menu_popup = (Text) findComponentById(ResourceTable.Id_text_menu_popup);

        btn_commonlist_popup = (Button) findComponentById(ResourceTable.Id_btn_commonlist_popup);
        btn_expandable_popup = (Button) findComponentById(ResourceTable.Id_btn_expandable_popup);
        btn_menu_popup = (Button) findComponentById(ResourceTable.Id_btn_menu_popup);
    }

    private void inintClickedListener() {
        image_back.setClickedListener(this);
        text_menu_popup.setClickedListener(this);
        btn_commonlist_popup.setClickedListener(this);
        btn_expandable_popup.setClickedListener(this);
        btn_menu_popup.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_text_menu_popup:
                PopupWindowDialog popupWindowDialog3=new PopupWindowDialog(mContext,text_menu_popup);
                popupWindowDialog3.setSize(350,395);
                popupWindowDialog3.setAutoClosable(true);
                popupWindowDialog3.setHasArrow(true);
                popupWindowDialog3.setArrowOffset(25);
                popupWindowDialog3.setmTvTitle("登录");
                popupWindowDialog3.setmTvMessage("筛选");
                popupWindowDialog3.setmTvAction("设置");
                popupWindowDialog3.setArrowSize(40,20);
                popupWindowDialog3.setmTvActionListener(component1 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog3.getmTvAction().getText().toString()+"");
                    popupWindowDialog3.destroy();
                });
                popupWindowDialog3.setmTvMessageListener(component12 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog3.getmTvMessage().getText().toString()+"");
                    popupWindowDialog3.destroy();
                });
                popupWindowDialog3.setmTvTitleListener(component13 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog3.getmTvTitle().getText().toString()+"");
                    popupWindowDialog3.destroy();
                });
                popupWindowDialog3.show();
                break;
            case ResourceTable.Id_btn_commonlist_popup:
                PopupWindowDialog popupWindowDialog=new PopupWindowDialog(mContext,btn_commonlist_popup);
                popupWindowDialog.setSize(350,380);
                popupWindowDialog.setAutoClosable(true);
                popupWindowDialog.setHasArrow(true);
                popupWindowDialog.setMode(IDialog.DEF_RADIUS);
                popupWindowDialog.setArrowSize(40,20);
                popupWindowDialog.setmTvActionListener(component1 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog.getmTvAction().getText().toString()+"");
                    popupWindowDialog.destroy();
                });
                popupWindowDialog.setmTvMessageListener(component12 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog.getmTvMessage().getText().toString()+"");
                    popupWindowDialog.destroy();
                });
                popupWindowDialog.setmTvTitleListener(component13 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog.getmTvTitle().getText().toString()+"");
                    popupWindowDialog.destroy();
                });
                popupWindowDialog.show();
                break;
            case ResourceTable.Id_btn_menu_popup:
                PopupWindowDialog popupWindowDialog2=new PopupWindowDialog(mContext,btn_menu_popup);
                popupWindowDialog2.setSize(350,395);
                popupWindowDialog2.setAutoClosable(true);
                popupWindowDialog2.setHasArrow(true);
                popupWindowDialog2.setArrowOffset(140);
                popupWindowDialog2.setmTvTitle("登录");
                popupWindowDialog2.setmTvMessage("筛选");
                popupWindowDialog2.setmTvAction("设置");
                popupWindowDialog2.setArrowSize(40,20);
                popupWindowDialog2.setmTvActionListener(component1 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog2.getmTvAction().getText().toString()+"");
                    popupWindowDialog2.destroy();
                });
                popupWindowDialog2.setmTvMessageListener(component12 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog2.getmTvMessage().getText().toString()+"");
                    popupWindowDialog2.destroy();
                });
                popupWindowDialog2.setmTvTitleListener(component13 -> {
                    ToastUtil.showToast(mContext,popupWindowDialog2.getmTvTitle().getText().toString()+"");
                    popupWindowDialog2.destroy();
                });
                popupWindowDialog2.show();
                break;
            case ResourceTable.Id_btn_expandable_popup:

                break;

        }
    }
}
